<template>
  <el-table :data="tableData" style="width: 100%">
    <el-table-column prop="name" label="姓名" width="180"> </el-table-column>
    <el-table-column prop="learningTime" label="学习时长"> </el-table-column>
  </el-table>
</template>
<style>
</style>
<script>
import { del, get } from "@/utils/request";
export default {
  data() {
    return {
      tableData: [],
      Data: [],
      sortdata: []
    };
  },
  methods: {
    async getlearningtime() {
      let url = "http://120.77.41.127:8080/nameUser/query";
      let data = await get(url);
      this.Data = data.data;
      for (let i = 0; i < this.Data.length; i++) {
        if (
          this.Data[i].learningTime != 0 &&
          this.Data[i].learningTime != null
        ) {
          this.tableData.push(this.Data[i]);
        }
      }
      this.tableData = this.tableData.sort(this.compare("learningTime"));
      console.log(this.tableData);
    },
    compare(property) {
      return function(a, b) {
        var value1 = a[property];
        var value2 = b[property];
        return value2 - value1;
      };
    }
  },
  mounted() {
    this.getlearningtime();
  }
};
</script>